package com.wwwarehouse.carddesk.fragment.teamfragment.checkdownclassfragemnt;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.carddesk.adapter.teamadapter.TeamSelectPermissionPagerAdapter;
import com.wwwarehouse.carddesk.bean.teambean.TeamAuthorizedOutItensBean;
import com.wwwarehouse.carddesk.constant.CardDeskConstant;
import com.wwwarehouse.carddesk.eventbus_event.TeamPREvent;
import com.wwwarehouse.carddesk.eventbus_event.TeamSelectPowerEvent;
import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.filter.FilterBean;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.CustomViewPagerInternal;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.SlideBarView;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.custom_widget.time_pick.DateUtil;
import com.wwwarehouse.common.eventbus_event.DrawerMultipleCompleteEvent;
import com.wwwarehouse.common.fragment.DeskDrawerMultipleFragment;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.LogUtils;
import com.wwwarehouse.common.tools.PopUpUtils;
import com.wwwarehouse.common.tripartite_widget.viewindicator.CirclePageIndicator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import de.greenrobot.event.EventBus;


/**
 * Created by xiaoke.ni on 2017/10/11.
 */

public class TeamPRFragment extends BaseFragment implements View.OnClickListener, TeamPRListFragment.OnButtonClickedListener {

    private View mView;

    private StateLayout             mStateLayout;
    private ElasticScrollView       mElasticScrollView;
    private CustomViewPagerInternal mCustomViewPagerInternal;
    private CirclePageIndicator     mCirclePagerIndicator;

    private TeamSelectPermissionPagerAdapter mViewPagerAdapter;

    private List<Fragment>                                                      mFragmentList;
    private List<FilterBean>                                                    mFilterList;
    private List<ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean>> mFragmentDataList;
    private List<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean>            mAuthorLinkedList;
    private TeamAuthorizedOutItensBean                                          mAuthorizedOutItensBean;

    private String mUserId;// "19001"
    private String mBusinessUnitId;//"111111"
    private int mSelectedBubblePosition = 2;
    private SlideBarView   mSlideBarView;
    private RelativeLayout mRlSelf;
    private LinearLayout   mEmptyLayout;
    private ImageView      mEmptyImg;
    private TextView       mEmptyTxt;
    private RelativeLayout mRlBt;
    private Button         mBtRecycle;
    private ArrayList      mCardIdList;
    private ArrayList      mCardNameList;
    private String mPersonName;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = View.inflate(mActivity, R.layout.fragment_pr_team, null);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initView();
        initEvent();
    }

    private void initView() {
        mBtRecycle = (Button) mView.findViewById(R.id.btn_sure);
        mStateLayout = (StateLayout) mView.findViewById(R.id.slt);
        mElasticScrollView = (ElasticScrollView) mView.findViewById(R.id.esv);
        mCustomViewPagerInternal = (CustomViewPagerInternal) mView.findViewById(R.id.cvpi);
        mCirclePagerIndicator = (CirclePageIndicator) mView.findViewById(R.id.cpi);
        mSlideBarView = (SlideBarView) mView.findViewById(R.id.sbv_slide);
        mRlBt = (RelativeLayout) mView.findViewById(R.id.rl_bt);
        mRlSelf = (RelativeLayout) mView.findViewById(R.id.rl_self);
        mEmptyLayout = findView(mView, R.id.ll_empty);
        mEmptyImg = findView(mView, R.id.iv_empty);
        mEmptyTxt = findView(mView, R.id.tv_empty);
        mBtRecycle.setOnClickListener(this);
        //放cardid的集合
        mCardIdList = new ArrayList<>();
        mCardNameList = new ArrayList<>();
    }

    private void initEvent() {
    }

    @Override
    public void onButtonClicked() {

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_sure) {

            mCardNameList.clear();
            mCardIdList.clear();
            for (int i = 0; i < mAuthorizedOutItensBean.getUserCardAuthorities().size(); i++) {
                if (mAuthorizedOutItensBean.getUserCardAuthorities().get(i).isSelecter()) {
                    mCardIdList.add(mAuthorizedOutItensBean.getUserCardAuthorities().get(i).getCardId());
                    mCardNameList.add(mAuthorizedOutItensBean.getUserCardAuthorities().get(i).getCardName());
                }
            }
            final TeamSetAuthorityTimeDialogFragment dialogFragment = TeamSetAuthorityTimeDialogFragment.newInstance();
            String message;
            if (mCardIdList.size() > 1) {
                message = String.format(getResources().getString(R.string.teamdesk_sure_recycle_powers), mPersonName, mCardNameList.get(0),mCardNameList.size(),mPersonName);
            } else {
                message = String.format(getResources().getString(R.string.teamdesk_sure_recycle_power),mPersonName,mCardNameList.get(0), mPersonName);
            }
            dialogFragment.setTitle(getResources().getString(R.string.teamdesk_user_pr_sure))
                    .setMessage(message)
                    .setCancelText(getResources().getString(R.string.teamdesk_user_pr_consider))
                    .setConfirmText(getResources().getString(R.string.teamdesk_user_pr_sure_recycling))
                    .setOnCancelClickListener(new TeamSetAuthorityTimeDialogFragment.onCancelClickListener() {
                        @Override
                        public void onCancelClick(View view, DialogFragment dialog) {

                            dialogFragment.dismiss();
                        }
                    })
                    .setOnConfirmClickListener(new TeamSetAuthorityTimeDialogFragment.OnConfirmClickListener() {
                        @Override
                        public void onConfirmClick(View view) {
                            mRlBt.setVisibility(View.INVISIBLE);
                            selectNum = 0;
                            dialogFragment.dismiss();
                            Bundle bundle = new Bundle();
                            bundle.putIntegerArrayList("cardIds", mCardIdList);
                            bundle.putString("beUserId", mUserId);
                            bundle.putString("businessId", mBusinessUnitId);
                            TeamPRSuccessFragment teamPRSuccessFragment = new TeamPRSuccessFragment();
                            teamPRSuccessFragment.setArguments(bundle);
                            pushFragment(teamPRSuccessFragment);
                        }
                    });
            dialogFragment.show(getFragmentManager(), "");
        }

    }

    @Override
    public void setTitle() {
        mActivity.setTitle(R.string.teamdesk_recycle_power);
    }

    @Override
    public void requestDatas() {
        if (getArguments() != null) {
            Bundle bundle = getArguments();
            mPersonName = bundle.getString("personName");
            mBusinessUnitId = bundle.getString("buId");
            mUserId = bundle.getString("userId");
        }
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        mFragmentList = new ArrayList<>();
        mFilterList = new ArrayList<>();
        mFragmentDataList = new ArrayList<>();
        mAuthorLinkedList = new ArrayList<>();
        mStateLayout.showProgressView(true);
        cardDeskOption();
        getAuthorizedOutItems();
    }

    @Override
    public void onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        super.onDestroy();
    }

    /**
     * 权限回收-查询用户可以回收的权限项
     */
    private void getAuthorizedOutItems() {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", mUserId);
        map.put("businessId", mBusinessUnitId);
        NoHttpUtils.httpPost(CardDeskConstant.GET_AUTHORIZED_OUT_ITENS_TEAM, map, onResponseListener, 0);
    }


    private NoHttpUtils.OnResponseListener onResponseListener = new NoHttpUtils.OnResponseListener() {
        @Override
        public void onSucceed(CommonClass commonClass, int what) {
            try {
                switch (what) {
                    case 0:
                        if (TextUtils.equals("0", commonClass.getCode())) {
                            mStateLayout.showContentView();
                            mAuthorizedOutItensBean = JSON.parseObject(commonClass.getData().toString(), TeamAuthorizedOutItensBean.class);
                            if (mAuthorizedOutItensBean.getTags() != null && mAuthorizedOutItensBean.getTags().size() > 0) {
                                /******** 设置侧滑菜单 *******/
                                for (TeamAuthorizedOutItensBean.TagsBean bean : mAuthorizedOutItensBean.getTags()) {
                                    mFilterList.add(new FilterBean(false, bean.getTagName()));
                                }
                                DeskDrawerMultipleFragment deskDrawerMultipleFragment = DeskDrawerMultipleFragment.newInstance("应用对象", mFilterList, 2);
                                ((BaseCardDeskActivity) mActivity).setDrawerLayout(deskDrawerMultipleFragment);
                                ((BaseCardDeskActivity) mActivity).disableDrawerLayout();
                                /******** 设置侧滑菜单 *******/

                                mAuthorLinkedList.addAll(mAuthorizedOutItensBean.getUserCardAuthorities());
                                // 默认排序：获取权限时间由近到远
                                Collections.sort(mAuthorLinkedList, new Comparator<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean>() {
                                    @Override
                                    public int compare(TeamAuthorizedOutItensBean.UserCardAuthoritiesBean o1, TeamAuthorizedOutItensBean.UserCardAuthoritiesBean o2) {
                                        Date date1 = DateUtil.formatDateStr(o1.getValidDate(), "yyyy-MM-dd HH:mm:ss");
                                        Date date2 = DateUtil.formatDateStr(o2.getValidDate(), "yyyy-MM-dd HH:mm:ss");
                                        if (date1.after(date2)) {
                                            return -1;
                                        } else if (date1.before(date2)) {
                                            return 1;
                                        } else {
                                            return 0;
                                        }
                                    }
                                });
                                // 分页
                                List<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> list = new ArrayList<>(); // 用来填装item的量具, 最大容量是30
                                for (int i = 0; i < mAuthorLinkedList.size(); i++) {
                                    list.add(mAuthorLinkedList.get(i));
                                    if (list.size() == 30 || i == mAuthorLinkedList.size() - 1) { // 当填满了30个item或者已经到总数的最后一个时, 将这一页加入到页的集合中
                                        ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> perPageList = new ArrayList<>();
                                        for (TeamAuthorizedOutItensBean.UserCardAuthoritiesBean itemBean : list) {
                                            perPageList.add(itemBean);
                                        }
                                        mFragmentDataList.add(perPageList); // 将这一页加入到页的集合中
                                        list = new ArrayList<>(); // 清空填装item的容器
                                    }
                                }

                                for (ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> dataList : mFragmentDataList) {
                                    TeamPRListFragment listFragment = TeamPRListFragment.newInstance(dataList, mBusinessUnitId);
                                    listFragment.setOnButtonClickedListener(TeamPRFragment.this);
                                    mFragmentList.add(listFragment);
                                }
                                mViewPagerAdapter = new TeamSelectPermissionPagerAdapter(getChildFragmentManager(), mFragmentList);
                                mCustomViewPagerInternal.setAdapter(mViewPagerAdapter);
                                if (mFragmentDataList.size() <= 6) {
                                    mCirclePagerIndicator.setVisibility(View.VISIBLE);
                                    mSlideBarView.setVisibility(View.GONE);
                                    mCirclePagerIndicator.setViewPager(mCustomViewPagerInternal, 0);
                                } else {
                                    mCirclePagerIndicator.setVisibility(View.GONE);
                                    mSlideBarView.setVisibility(View.VISIBLE);
                                    mSlideBarView.setTotalPage(mFragmentDataList.size());
                                    mSlideBarView.setOnSlideChange(new SlideBarView.OnSlideChange() {
                                        @Override
                                        public void onSlideChange(int i) {
                                            mCustomViewPagerInternal.setCurrentItem(mFragmentDataList.size(), false);
                                        }
                                    });
                                    mSlideBarView.setViewPagerInternal(mCustomViewPagerInternal);
                                }
                            }else {
                                mStateLayout.showEmptyView(commonClass.getMsg(), true);
                                mStateLayout.setEmptyListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        getAuthorizedOutItems();
                                    }
                                });
                                //                        ToastUtils.showToast(commonClass.getMsg());
                            }
                        }
                        break;
                    default:
                        break;
                }
            } catch (Exception e) {
                LogUtils.showLog(e.toString());
            }


        }

        @Override
        public void onFailed(String s, int i) {
            mStateLayout.showSystemView(true);
            mStateLayout.setSystemListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getAuthorizedOutItems();
                }
            });
        }

        @Override
        public void onFinish(int i) {
            mStateLayout.showContentView();
        }
    };

    @Override
    public void sortClick(View anchor) {
        if (peekFragment() instanceof TeamPRFragment) {
            PopUpUtils.showBubbleInviteSort(getContext(), anchor, mSelectedBubblePosition, new PopUpUtils.OnChoiceListener() {
                @Override
                public void onChoice(int position) {
                    mSelectedBubblePosition = position;

                    switch (position) {
                        case 1:
                            // 获取权限时间由远到近
                            Collections.sort(mAuthorLinkedList, new Comparator<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean>() {
                                @Override
                                public int compare(TeamAuthorizedOutItensBean.UserCardAuthoritiesBean o1, TeamAuthorizedOutItensBean.UserCardAuthoritiesBean o2) {
                                    Date date1 = DateUtil.formatDateStr(o1.getValidDate(), "yyyy-MM-dd HH:mm:ss");
                                    Date date2 = DateUtil.formatDateStr(o2.getValidDate(), "yyyy-MM-dd HH:mm:ss");
                                    if (date1.after(date2)) {
                                        return 1;
                                    } else if (date1.before(date2)) {
                                        return -1;
                                    } else {
                                        return 0;
                                    }
                                }
                            });
                            break;
                        case 2:
                            // 获取权限时间由近到远
                            Collections.sort(mAuthorLinkedList, new Comparator<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean>() {
                                @Override
                                public int compare(TeamAuthorizedOutItensBean.UserCardAuthoritiesBean o1, TeamAuthorizedOutItensBean.UserCardAuthoritiesBean o2) {
                                    Date date1 = DateUtil.formatDateStr(o1.getValidDate(), "yyyy-MM-dd HH:mm:ss");
                                    Date date2 = DateUtil.formatDateStr(o2.getValidDate(), "yyyy-MM-dd HH:mm:ss");
                                    if (date1.after(date2)) {
                                        return -1;
                                    } else if (date1.before(date2)) {
                                        return 1;
                                    } else {
                                        return 0;
                                    }
                                }
                            });

                            break;
                        default:
                            break;
                    }
                    mFragmentDataList.clear();
                    // 分页
                    List<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> list = new ArrayList<>(); // 用来填装item的量具, 最大容量是30
                    for (int i = 0; i < mAuthorLinkedList.size(); i++) {
                        list.add(mAuthorLinkedList.get(i));
                        if (list.size() == 30 || i == mAuthorLinkedList.size() - 1) { // 当填满了30个item或者已经到总数的最后一个时, 将这一页加入到页的集合中
                            ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> perPageList = new ArrayList<>();
                            for (TeamAuthorizedOutItensBean.UserCardAuthoritiesBean itemBean : list) {
                                perPageList.add(itemBean);
                            }
                            mFragmentDataList.add(perPageList); // 将这一页加入到页的集合中
                            list = new ArrayList<>(); // 清空填装item的容器
                        }
                    }
                    mFragmentList.clear();
                    for (ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> dataList : mFragmentDataList) {
                        TeamPRListFragment listFragment = TeamPRListFragment.newInstance(dataList, mBusinessUnitId);
                        listFragment.setOnButtonClickedListener(TeamPRFragment.this);
                        mFragmentList.add(listFragment);
                    }
                    mCustomViewPagerInternal.removeAllViews();
                    mViewPagerAdapter = new TeamSelectPermissionPagerAdapter(getChildFragmentManager(), mFragmentList);
                    mCustomViewPagerInternal.setAdapter(mViewPagerAdapter);
                    mCirclePagerIndicator.setViewPager(mCustomViewPagerInternal);
                    mViewPagerAdapter.notifyDataSetChanged();
                }
            }, null, mActivity.getResources().getString(R.string.teamdesk_get_time_yuan_to_jin), mActivity.getResources().getString(R.string.teamdesk_get_time_jin_to_yuan));
        }
    }

    private String searchText = "";

    @Override
    public void searchNoRealTimeClick(String text) {
        if (peekFragment() instanceof TeamPRFragment) {
            searchText = text;

            List<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> tempList = new ArrayList<>();
            for (TeamAuthorizedOutItensBean.UserCardAuthoritiesBean itemBean : mAuthorLinkedList) {
                if (itemBean.getCardName() != null && itemBean.getCardName().contains(text)) {
                    tempList.add(itemBean);
                }
            }

            mFragmentDataList.clear();
            if (tempList.size() == 0) {
                mRlSelf.setVisibility(View.GONE);
                mEmptyLayout.setVisibility(View.VISIBLE);
                mEmptyImg.setImageResource(R.drawable.search_empty);
                mEmptyTxt.setText(R.string.invite_search_no_result);
            } else {
                mRlSelf.setVisibility(View.VISIBLE);
                mEmptyLayout.setVisibility(View.GONE);
                // 分页
                List<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> list = new ArrayList<>(); // 用来填装item的量具, 最大容量是30
                for (int i = 0; i < tempList.size(); i++) {
                    list.add(tempList.get(i));
                    if (list.size() == 30 || i == tempList.size() - 1) { // 当填满了30个item或者已经到总数的最后一个时, 将这一页加入到页的集合中
                        ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> perPageList = new ArrayList<>();
                        for (TeamAuthorizedOutItensBean.UserCardAuthoritiesBean itemBean : list) {
                            perPageList.add(itemBean);
                        }
                        mFragmentDataList.add(perPageList); // 将这一页加入到页的集合中
                        list = new ArrayList<>(); // 清空填装item的容器
                    }
                }
                mFragmentList.clear();
                for (ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> dataList : mFragmentDataList) {
                    TeamPRListFragment listFragment = TeamPRListFragment.newInstance(dataList, mBusinessUnitId);
                    listFragment.setOnButtonClickedListener(TeamPRFragment.this);
                    mFragmentList.add(listFragment);
                }
                mCustomViewPagerInternal.removeAllViews();
                mViewPagerAdapter = new TeamSelectPermissionPagerAdapter(getChildFragmentManager(), mFragmentList);
                mCustomViewPagerInternal.setAdapter(mViewPagerAdapter);
                mCirclePagerIndicator.setViewPager(mCustomViewPagerInternal);
                mCirclePagerIndicator.requestLayout();
                mViewPagerAdapter.notifyDataSetChanged();
            }

        }


    }

    private void cardDeskOption() {
        mElasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {
                ((BaseCardDeskActivity) mActivity).downPull_4();
                ((BaseCardDeskActivity) mActivity).showFilterBt();
                ((BaseCardDeskActivity) mActivity).showSortBt();

            }

            @Override
            public void onUpPull() {

            }
        });

    }


    @Override
    public void filterClick() {
        if (peekFragment() instanceof TeamPRFragment) {
            ((BaseCardDeskActivity) mActivity).showDrawerLayout();
        }
    }

    @Override
    public void cancelClick() {
        if (peekFragment() instanceof TeamPRFragment) {
            mRlSelf.setVisibility(View.VISIBLE);
            mEmptyLayout.setVisibility(View.GONE);
            mFragmentDataList.clear();
            // 分页
            List<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> list = new ArrayList<>(); // 用来填装item的量具, 最大容量是30
            for (int i = 0; i < mAuthorLinkedList.size(); i++) {
                list.add(mAuthorLinkedList.get(i));
                if (list.size() == 30 || i == mAuthorLinkedList.size() - 1) { // 当填满了30个item或者已经到总数的最后一个时, 将这一页加入到页的集合中
                    ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> perPageList = new ArrayList<>();
                    for (TeamAuthorizedOutItensBean.UserCardAuthoritiesBean itemBean : list) {
                        perPageList.add(itemBean);
                    }
                    mFragmentDataList.add(perPageList); // 将这一页加入到页的集合中
                    list = new ArrayList<>(); // 清空填装item的容器
                }
            }
            mFragmentList.clear();
            for (ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> dataList : mFragmentDataList) {
                TeamPRListFragment listFragment = TeamPRListFragment.newInstance(dataList, mBusinessUnitId);
                listFragment.setOnButtonClickedListener(TeamPRFragment.this);
                mFragmentList.add(listFragment);
            }
            mCustomViewPagerInternal.removeAllViews();
            mViewPagerAdapter = new TeamSelectPermissionPagerAdapter(getChildFragmentManager(), mFragmentList);
            mCustomViewPagerInternal.setAdapter(mViewPagerAdapter);
            mCirclePagerIndicator.setViewPager(mCustomViewPagerInternal);
            mViewPagerAdapter.notifyDataSetChanged();
        }

    }

    private int selectNum;

    public void onEventMainThread(TeamSelectPowerEvent teamSelectPowerEvent) {
        if (teamSelectPowerEvent.isShow()) {
            selectNum += 1;
        } else {
            selectNum -= 1;
        }
        if (selectNum >= 1) {
            mRlBt.setVisibility(View.VISIBLE);
        } else {
            mRlBt.setVisibility(View.INVISIBLE);
        }
    }

    //刷新数据
    public void onEventMainThread(TeamPREvent event) {
        String message = event.getMsg();
        if ("pr_refresh".equals(message)) {
            mFragmentList = new ArrayList<>();
            mFilterList = new ArrayList<>();
            mFragmentDataList = new ArrayList<>();
            mAuthorLinkedList = new ArrayList<>();
            mStateLayout.showProgressView(true);
            cardDeskOption();
            getAuthorizedOutItems();
        }
    }

    public void onEventMainThread(DrawerMultipleCompleteEvent event) {
        if (!(peekFragment() instanceof TeamPRFragment) && mAuthorizedOutItensBean != null) {
            return;
        }
        ((BaseCardDeskActivity) mActivity).hideDrawerLayout();
        Set<Integer> set = event.getSelectedPositionSet();
        List<String> filterBeanList = new ArrayList<>();
        if (set.isEmpty()) {
            for (FilterBean filterBean : mFilterList) {
                filterBeanList.add(filterBean.getText());
            }
        } else {
            for (Integer i : set) {
                filterBeanList.add(mFilterList.get(i).getText());
            }
        }
        mAuthorLinkedList.clear();
        for (TeamAuthorizedOutItensBean.UserCardAuthoritiesBean itemBean : mAuthorizedOutItensBean.getUserCardAuthorities()) {
            if (filterBeanList.contains(itemBean.getTagName())) {
                mAuthorLinkedList.add(itemBean);
            }
        }

        mFragmentDataList.clear();
        // 分页
        List<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> list = new ArrayList<>(); // 用来填装item的量具, 最大容量是30
        for (int i = 0; i < mAuthorLinkedList.size(); i++) {
            list.add(mAuthorLinkedList.get(i));
            if (list.size() == 30 || i == mAuthorLinkedList.size() - 1) { // 当填满了30个item或者已经到总数的最后一个时, 将这一页加入到页的集合中
                ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> perPageList = new ArrayList<>();
                for (TeamAuthorizedOutItensBean.UserCardAuthoritiesBean itemBean : list) {
                    perPageList.add(itemBean);
                }
                mFragmentDataList.add(perPageList); // 将这一页加入到页的集合中
                list = new ArrayList<>(); // 清空填装item的容器
            }
        }
        mFragmentList.clear();
        for (ArrayList<TeamAuthorizedOutItensBean.UserCardAuthoritiesBean> dataList : mFragmentDataList) {
            TeamPRListFragment listFragment = TeamPRListFragment.newInstance(dataList, mBusinessUnitId);
            listFragment.setOnButtonClickedListener(TeamPRFragment.this);
            mFragmentList.add(listFragment);
        }
        mCustomViewPagerInternal.removeAllViews();
        mViewPagerAdapter = new TeamSelectPermissionPagerAdapter(getChildFragmentManager(), mFragmentList);
        mCustomViewPagerInternal.setAdapter(mViewPagerAdapter);
        mCirclePagerIndicator.setViewPager(mCustomViewPagerInternal);
        mCirclePagerIndicator.requestLayout();
        mViewPagerAdapter.notifyDataSetChanged();

    }

}
